@echo off
rem 像素生存者游戏构建脚本 (Windows版本)
rem 将所有模块合并成单个game.js文件

echo 🚀 开始构建像素生存者游戏...

rem 创建构建目录
if not exist build mkdir build

rem 输出文件
set output_file=build\game.js

rem 清空输出文件
type nul > "%output_file%"

echo 📦 合并JavaScript文件...

rem 添加文件头注释
echo // 像素生存者游戏 - 构建版本 >> "%output_file%"
echo // 构建时间: %date% %time% >> "%output_file%"
echo // ======================================== >> "%output_file%"
echo. >> "%output_file%"

rem 按依赖顺序合并文件
echo   ✅ 合并: src/core/GameConfig.js
echo // === src/core/GameConfig.js === >> "%output_file%"
type "src\core\GameConfig.js" >> "%output_file%"
echo. >> "%output_file%"

echo   ✅ 合并: src/core/SpriteCreator.js
echo // === src/core/SpriteCreator.js === >> "%output_file%"
type "src\core\SpriteCreator.js" >> "%output_file%"
echo. >> "%output_file%"

echo   ✅ 合并: src/utils/EffectSystem.js
echo // === src/utils/EffectSystem.js === >> "%output_file%"
type "src\utils\EffectSystem.js" >> "%output_file%"
echo. >> "%output_file%"

echo   ✅ 合并: src/utils/TouchController.js
echo // === src/utils/TouchController.js === >> "%output_file%"
type "src\utils\TouchController.js" >> "%output_file%"
echo. >> "%output_file%"

echo   ✅ 合并: src/systems/WeaponSystem.js
echo // === src/systems/WeaponSystem.js === >> "%output_file%"
type "src\systems\WeaponSystem.js" >> "%output_file%"
echo. >> "%output_file%"

echo   ✅ 合并: src/systems/EnemySystem.js
echo // === src/systems/EnemySystem.js === >> "%output_file%"
type "src\systems\EnemySystem.js" >> "%output_file%"
echo. >> "%output_file%"

echo   ✅ 合并: src/systems/UpgradeSystem.js
echo // === src/systems/UpgradeSystem.js === >> "%output_file%"
type "src\systems\UpgradeSystem.js" >> "%output_file%"
echo. >> "%output_file%"

echo   ✅ 合并: src/systems/AchievementSystem.js
echo // === src/systems/AchievementSystem.js === >> "%output_file%"
type "src\systems\AchievementSystem.js" >> "%output_file%"
echo. >> "%output_file%"

echo   ✅ 合并: src/ui/UISystem.js
echo // === src/ui/UISystem.js === >> "%output_file%"
type "src\ui\UISystem.js" >> "%output_file%"
echo. >> "%output_file%"

echo   ✅ 合并: src/ui/MenuScenes.js
echo // === src/ui/MenuScenes.js === >> "%output_file%"
type "src\ui\MenuScenes.js" >> "%output_file%"
echo. >> "%output_file%"

echo   ✅ 合并: src/core/PixelSurvivor.js
echo // === src/core/PixelSurvivor.js === >> "%output_file%"
type "src\core\PixelSurvivor.js" >> "%output_file%"
echo. >> "%output_file%"

rem 添加游戏启动代码
echo // === 游戏启动 === >> "%output_file%"
echo const game = new Phaser.Game^(GameConfig.config^); >> "%output_file%"

echo 📋 复制其他必要文件...

rem 复制并更新HTML文件
if exist "index.html" (
    echo   ✅ 更新 index.html
    powershell -Command "(Get-Content 'index.html') -replace 'src=\"src.*?\"', '' -replace 'src=\"phaser.min.js\"', 'src=\"phaser.min.js\"' -replace '<!-- 核心模块 -->.*?</script>', '<script src=\"game.js\"></script>' | Set-Content 'build/index.html'"
) else (
    echo   ❌ index.html 不存在
)

rem 复制Phaser库
if exist "phaser.min.js" (
    echo   ✅ 复制 phaser.min.js
    copy "phaser.min.js" "build\" > nul
) else (
    echo   ❌ phaser.min.js 不存在
)

echo.
echo ✨ 构建完成！
echo 📁 构建文件位置: build\
echo 🎮 游戏文件: build\game.js
echo.
echo 🌐 运行游戏:
echo    cd build
echo    python -m http.server 8000
echo    然后打开: http://localhost:8000
echo.
echo 🎉 构建成功！游戏已准备就绪。

pause